﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WMS.FC.Domain.PersistenceObject.Business;
using WMS.FC.Infrastructure.Common;

namespace WMS.FC.Infrastructure.POConfig.Business
{
    public class TrayConfig : POBaseConfig<TrayPO>
    {
        public override void InitializeData(EntityTypeBuilder<TrayPO> builder)
        {
        }

        public override void MapColumn(EntityTypeBuilder<TrayPO> builder, ref int index)
        {
            builder.HasComment("托盘表");
            builder.Property(entity => entity.Barcode).ConfigColumn("BARCODE", "托盘条码", 50, true).HasColumnOrder(index++);
            builder.Property(entity => entity.StateCode).ConfigColumn("STATE_CODE", "状态编码", 50, true).HasColumnOrder(index++);
            builder.Property(entity => entity.MaterialCode).ConfigColumn("MATERIAL_CODE", "物料编码", 50, true).HasColumnOrder(index++);
            builder.Property(entity => entity.TechnologyRouteCode).ConfigColumn("TECHNOLOGY_ROUTE_CODE", "工艺路径编码", 50, true).HasColumnOrder(index++);
            builder.Property(entity => entity.TechnologyProcessCode).ConfigColumn("TECHNOLOGY_PROCESS_CODE", "工艺工序编码", 50, true).HasColumnOrder(index++);
            builder.Property(entity => entity.ContainerBarcode).ConfigColumn("CONTAINER_BARCODE", "容器条码", 50, true).HasColumnOrder(index++);
            builder.Property(entity => entity.TrayPosition).ConfigColumn("TRAY_POSITION", "托盘位置").HasColumnOrder(index++);
            builder.Property(entity => entity.LastStationCode).ConfigColumn("LAST_STATION_CODE", "最后经过站台编码", 50).HasColumnOrder(index++);
            builder.Property(entity => entity.LastStationTime).ConfigColumn("LAST_STATION_TIME", "最后经过站台时间").HasColumnOrder(index++);
            builder.Property(entity => entity.TargetStationCode).ConfigColumn("TARGET_STATION_CODE", "目标站台编码", 50).HasColumnOrder(index++);
            builder.Property(entity => entity.WarehouseCode).ConfigColumn("WAREHOUSE_CODE", "仓库编码", 50, true).HasColumnOrder(index++);
        }

        public override void MapIndex(EntityTypeBuilder<TrayPO> builder)
        {
            builder.HasIndex(entity => new { entity.Barcode, entity.WarehouseCode }).HasDatabaseName($"UN_{TableName}_1").IsUnique();
        }
    }
}
